package com.example.com.shydemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import proxydroid.org.proxydroid.Profile;
import proxydroid.org.proxydroid.ProxyDroidService;

public class MainActivity extends AppCompatActivity {
    EditText edtTxtShow;

    Button btnProxyTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取编辑框，并设置自动滚动
        edtTxtShow = (EditText) findViewById(R.id.edtTxtShow);
        edtTxtShow.setMovementMethod(ScrollingMovementMethod.getInstance());
        edtTxtShow.setSelection(edtTxtShow.getText().length(), edtTxtShow.getText().length());

        //各种按钮
        btnProxyTest = (Button)findViewById(R.id.btnProxyTest);


        //===========================================================================
        //获取代理测试那妞
        //===========================================================================
        btnProxyTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String json = "{\n" +
                        "\t\"port\": 3128,\n" +
                        "\t\"host\": \"192.168.0.152\",\n" +
                        "\t\"isBypassApps\": false,\n" +
                        "\t\"isNTLM\": false,\n" +
                        "\t\"isAutoSetProxy\": false,\n" +
                        "\t\"password\": \"\",\n" +
                        "\t\"isPAC\": false,\n" +
                        "\t\"bypassAddrs\": \"\",\n" +
                        "\t\"isAuth\": false,\n" +
                        "\t\"proxyedApp\": \"com.jky.earn100\",\n" +
                        "\t\"proxyType\": \"socks5\",\n" +
                        "\t\"name\": \"192.168.0.15:3128.http\",\n" +
                        "\t\"isDNSProxy\": false,\n" +
                        "\t\"domain\": \"\",\n" +
                        "\t\"ssid\": \"\",\n" +
                        "\t\"user\": \"\",\n" +
                        "\t\"isAutoConnect\": false\n" +
                        "\t\"exeFilePath\": \"/data/local/tmp/proxy_test\",\n" +
                        "\t\"pluginWorkPath\": \"/data/local/tmp/proxy_test\",\n" +
                        "}\n";
                Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
                Profile profile = gson.fromJson(json, Profile.class);

                ProxyDroidService proxyDroidService = new ProxyDroidService(profile);
                proxyDroidService.startProxy();

            }
        });


    }
}
